package controllers

import (
	"fs_oms/models"
	"github.com/astaxie/beego"
)

type AddSubController struct {
	beego.Controller
}

func (c *AddSubController) Get() {
	c.TplName = "addsub.tpl"
}

func (c *AddSubController) Post() {
	var accountcode = c.GetString("accountcode")
	var password = c.GetString("password")
	if models.IsSubscriberExist(accountcode) {
		c.Data["result"] = "用户" + accountcode + "已经存在!"
	} else {
		err := models.AddSubscriber(accountcode, password)
		if err != nil {
			c.Data["result"] = "增加用户" + accountcode + "失败!"
			c.Data["reason"] = err.Error()
		} else {
			models.SyncData()
			c.Data["result"] = "增加用户" + accountcode + "成功!"
		}
	}

	c.TplName = "addsub_result.tpl"
}
